// orderresult.js
var api = require('../../utils/api');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    searchOrder: {
      orderNo: "",
      orderStatus: [],
      createId: "",
      id: ""
    },order_detail: {
    },
    hiddenmodalnotice: true,
    hiddenmodalinput: true,
    hiddenmodalrefund:true,
    nocancel:true,
    timeTableList:[],
    orderFlag:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var id = options.id;
    var orderNo = options.orderNo;
    this.data.searchOrder.id=id;
    this.data.searchOrder.orderNo=orderNo;
    
    var createId = app.globalData.opendId;
    this.data.searchOrder.createId = createId;
    
    this.getOrderDetail();
  },
  getOrderDetail: function () {
	var url2 = api.getQrCode();  
    var url = api.getOrderDetailUrl();
    var params = this.data.searchOrder;
    var that = this;
    api.request(url, 'POST', params, function (res, err) {
      var flag = false;
      var localUrl = url2 + "?url=";
      debugger;
      //已支付的订单
      if (res.orderStatus == "1") {
        flag = false;
        var userList = res.userList;
 
        for (var i = 0; i < userList.length;i++){
          //票 1.已锁定2.待使用3.已改签显示退票按钮
          if ((userList[i].statusCode == "1" || userList[i].statusCode == "2" || userList[i].statusCode == "3") && userList[i].refundPrice!="-1"){
            userList[i].fefundTicketFlag=false;
            userList[i].qrcode=encodeURI(localUrl + userList[i].qrcode);
          }else{
            userList[i].fefundTicketFlag = true;
            userList[i].qrcode=encodeURI(localUrl + userList[i].qrcode);
          }
         
        }
      }else{
        flag=true;
      }
      res.userList=userList;

      that.setData({ order_detail: res, orderFlag:flag });
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }, changetext: function () {
    wx.redirectTo({
      url: '../index/index'
    })
  },
  gpshowModal: function () {
    this.setData({
      hiddenmodalnotice: !this.data.hiddenmodalnotice
    })
  },
  gpcancel: function () {
    this.setData({
      hiddenmodalnotice: true
    })
  },
  gpconfirm: function () {
    this.setData({
      hiddenmodalnotice: !this.data.hiddenmodalnotice
    })
  },
  modalinput: function (e) {
    var url = api.getTimeTable();
    var that = this;
    api.request(url, 'GET', { 'staId': e.currentTarget.dataset.statid}, function (res, err) {
      that.setData({
        hiddenmodalinput: !that.data.hiddenmodalinput,
        timeTableList: res
      })
    });

    this.setData({
      hiddenmodalinput: !this.data.hiddenmodalinput,
      timeTableList : tempList
    })
   
  },
  skcancel: function () {
    this.setData({
      hiddenmodalinput: true
    })
  },
  skconfirm: function () {
    this.setData({
      hiddenmodalinput: !this.data.hiddenmodalinput
    })
  },
  
  modalrefund: function () {
    if (this.data.order_detail.orderStatus == "1"){
      var dataList = this.data.order_detail.userList;
      var resList = [];
      var res={};
      res = this.data.order_detail;
      for (var i = 0; i < dataList.length;i++){
        dataList[i].fefundTicketFlag=false;
        resList.push(dataList[i]);
      }
      this.data.userList = resList;
      res.userList = resList;
    }
/*
    this.setData({
      hiddenmodalrefund: !this.data.hiddenmodalrefund,
      order_detail:res
    })
*/
  },
  recancel: function () {
    this.setData({
      hiddenmodalrefund: true
    })
  },
  reconfirm: function (e) {
    debugger;
    this.setData({
      hiddenmodalrefund: !this.data.hiddenmodalrefund
    })
  },
  /**
   * 二维码弹框
   */
  /**在线选座弹框
   * 
   */
  showModal: function () {
    // 显示遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    this.setData({
      animationData: animation.export(),
      showModalStatus: true
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 200)
  },
  hideModal: function () {
    // 隐藏遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export(),
        showModalStatus: false
      })
    }.bind(this), 200)
  },
  refundTicket:function(e){
	debugger;
    var id = this.data.searchOrder.id;
    var createId = this.data.searchOrder.createId;
    var orderNo = this.data.searchOrder.orderNo;
    var ticketId = e.detail.target.dataset.ticketid;
    var orderid = e.detail.target.dataset.orderid;

    wx.navigateTo({
      url: '../orderback/orderback?id=' + "" + "&createId=" + createId + "&orderNo=" + orderNo + "&ticketId=" + ticketId + "&orderId="+orderid,
    })

    /*
    var that = this;
    this.data.hiddenmodalrefund=true;
    this.setData({
      hiddenmodalrefund: !this.data.hiddenmodalrefund
    })

    var url = api.refundTicket();
    var opendId = app.globalData.opendId;
    var orderId = e.detail.target.dataset.orderid;
    var ticketId = e.detail.target.dataset.ticketid;
debugger;
    var params = { "opendId": opendId, "orderId": orderId, "ticketId": ticketId, "formId": e.detail.formId};
    api.request(url, 'POST', params, function (res1, err) {
      debugger;
      wx.showToast({
        title: '退票成功！',
        icon: 'success',
        duration: 2500
      })
    });*/
  }
})